/**
 * Copyright (C) 2018-2020
 * All rights reserved, Designed By www.yixiang.co
 * 注意：
 * 本软件为www.yixiang.co开发研制，未经购买不得使用
 * 购买后可获得全部源代码（禁止转卖、分享、上传到码云、github等开源平台）
 * 一经发现盗用、分享等行为，将追究法律责任，后果自负
 */
package co.yixiang.modules.services;

import cn.binarywang.wx.miniapp.api.WxMaQrcodeService;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.WxMaCodeLineColor;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.img.ImgUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.qrcode.QrCodeUtil;
import cn.hutool.http.HttpUtil;
import co.yixiang.api.YshopException;
import co.yixiang.constant.ShopConstants;
import co.yixiang.constant.SystemConfigConstants;
import co.yixiang.enums.AppFromEnum;
import co.yixiang.enums.OrderInfoEnum;
import co.yixiang.modules.activity.domain.YxStoreBargain;
import co.yixiang.modules.activity.domain.YxStoreBargainUser;
import co.yixiang.modules.activity.domain.YxStoreCombination;
import co.yixiang.modules.activity.domain.YxStorePink;
import co.yixiang.modules.activity.service.YxStoreBargainService;
import co.yixiang.modules.activity.service.YxStoreBargainUserService;
import co.yixiang.modules.activity.service.YxStoreCombinationService;
import co.yixiang.modules.activity.service.YxStorePinkService;
import co.yixiang.modules.mp.config.WxMaConfiguration;
import co.yixiang.modules.order.vo.YxStoreOrderQueryVo;
import co.yixiang.modules.product.domain.YxStoreProduct;
import co.yixiang.modules.product.service.YxStoreProductService;
import co.yixiang.modules.shop.domain.YxSystemAttachment;
import co.yixiang.modules.shop.service.YxSystemAttachmentService;
import co.yixiang.modules.shop.service.YxSystemConfigService;
import co.yixiang.modules.shop.service.YxSystemStoreService;
import co.yixiang.modules.user.domain.YxUser;
import co.yixiang.modules.user.service.YxUserService;
import co.yixiang.utils.OrderUtil;
import co.yixiang.utils.RedisUtil;
import co.yixiang.utils.RedisUtils;
import co.yixiang.utils.ShopKeyUtils;
import com.alibaba.fastjson.JSONObject;
import com.sun.imageio.plugins.common.ImageUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import org.apache.poi.ss.util.ImageUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;

import javax.imageio.ImageIO;
import javax.imageio.stream.ImageInputStream;
import java.awt.Color;
import java.awt.Font;
import java.awt.FontFormatException;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URL;
import java.util.*;
import java.util.concurrent.TimeUnit;

import static co.yixiang.utils.FileUtil.transformStyle;

@Slf4j
@Service
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class CreatShareProductService {

    private final YxSystemAttachmentService systemAttachmentService;
    private final YxStoreBargainService storeBargainService;
    private final YxStoreBargainUserService storeBargainUserService;
    private final YxStorePinkService storePinkService;
    private final YxStoreCombinationService storeCombinationService;
    private final YxSystemStoreService systemStoreService;
    private final YxSystemConfigService systemConfigService;
    private final YxStoreProductService storeProductService;
    private final YxUserService yxUserService;
    private final RedisUtils redisUtils;

    @Autowired
    private RedisTemplate<String, String> redisTemplate;

    /**
     * 返回门店信息与二维码
     * @param storeOrder 订单
     * @return YxStoreOrderQueryVo
     */
    public YxStoreOrderQueryVo handleQrcode(YxStoreOrderQueryVo storeOrder,String path){
        //门店
        if(OrderInfoEnum.SHIPPIING_TYPE_2.getValue().equals(storeOrder.getShippingType())){
            String mapKey = RedisUtil.get(SystemConfigConstants.TENGXUN_MAP_KEY);
            if(StrUtil.isBlank(mapKey)) {
                throw new YshopException("请配置腾讯地图key");
            }
            String apiUrl = systemConfigService.getData(SystemConfigConstants.API_URL);
            if(StrUtil.isEmpty(apiUrl)){
                throw new YshopException("未配置api地址");
            }
            //生成二维码
            String name = storeOrder.getVerifyCode()+"_yshop.jpg";
            YxSystemAttachment attachment = systemAttachmentService.getInfo(name);
            String fileDir = path+"qrcode"+ File.separator;
            String qrcodeUrl = "";
            if(ObjectUtil.isNull(attachment)){
                //生成二维码
                File file = FileUtil.mkdir(new File(fileDir));
                QrCodeUtil.generate(storeOrder.getVerifyCode(), 180, 180,
                        FileUtil.file(fileDir+name));
                systemAttachmentService.attachmentAdd(name,String.valueOf(FileUtil.size(file)),
                        fileDir+name,"qrcode/"+name);
                qrcodeUrl = apiUrl + "/api/file/qrcode/"+name;
            }else{
                qrcodeUrl = apiUrl + "/api/file/" + attachment.getSattDir();
            }
            storeOrder.setCode(qrcodeUrl);
            storeOrder.setMapKey(mapKey);
            storeOrder.setSystemStore(systemStoreService.getYxSystemStoreById(storeOrder.getStoreId()));
        }

        return storeOrder;
    }

    /**
     * 获取分销二维码url
     * @param from 来源
     * @param userInfo 用户
     * @param siteUrl h5地址
     * @param apiUrl api地址
     * @param path 本地图片路径
     * @return url
     */
    public String getSpreadUrl(String from,YxUser userInfo,String siteUrl,
                               String apiUrl,String path){
        String spreadUrl = "";
        Long uid = userInfo.getUid();
        log.info("开始===============");
        log.info("用户ID==============="+uid);
        String wechatSpreadImg =systemConfigService.getData(ShopConstants.WECHAT_SPREAD_IMG);
        //File newFile = FileUtil.file("fx7.jpg");
        //log.info("newFile==============="+newFile);
        File newFileT = new File("simsunb.ttf");
        try {
            /*if(!newFile.exists()){
                InputStream stream =  getClass().getClassLoader().getResourceAsStream("fx.jpg");
                FileUtils.copyInputStreamToFile(stream, newFile);
            }*/
            if(!newFileT.exists()){
                InputStream streamT =  getClass().getClassLoader()
                        .getResourceAsStream("simsunb.ttf");
                FileUtils.copyInputStreamToFile(streamT, newFileT);
            }
        } catch (IOException e) {
            log.error(e.getMessage());
            throw new YshopException(e.getMessage());
        }

        if(StrUtil.isNotBlank(from) && AppFromEnum.APP.getValue().equals(from)){
            String spreadPicName = uid + "_"+from+"_user_spread.jpg";
            String fileDir = path+"qrcode"+File.separator;
            String spreadPicPath = fileDir+spreadPicName;

            YxSystemAttachment attachmentT = systemAttachmentService.getInfo(spreadPicName);
            log.info("attachmentT==============="+attachmentT);
            if(ObjectUtil.isNull(attachmentT)){
                try {
                    Font font =  Font.createFont(Font.TRUETYPE_FONT, newFileT);
                    Font f= font.deriveFont(Font.PLAIN,20);
                    ImgUtil.pressText(//
                            FileUtil.file(wechatSpreadImg),
                            //newFile,
                            FileUtil.file(spreadPicPath),
                            userInfo.getNickname()+"邀您加入",
                            Color.BLACK,
                            f, //字体
                            0, //x坐标修正值。 默认在中间，偏移量相对于中间偏移
                            300, //y坐标修正值。 默认在中间，偏移量相对于中间偏移
                            0.8f//透明度：alpha 必须是范围 [0.0, 1.0] 之内（包含边界值）的一个浮点数字
                    );

                    String inviteCode =  OrderUtil.createShareCode();
                    ImgUtil.pressText(
                            FileUtil.file(spreadPicPath),
                            FileUtil.file(spreadPicPath),
                            "邀您码:"+ inviteCode,
                            Color.RED,
                            f, //字体
                            0, //x坐标修正值。 默认在中间，偏移量相对于中间偏移
                            340, //y坐标修正值。 默认在中间，偏移量相对于中间偏移
                            0.8f
                    );

                    systemAttachmentService.newAttachment4SpreadAdd(spreadPicName,
                            String.valueOf(FileUtil.size(new File(spreadPicPath))),
                            spreadPicPath,"qrcode/"+spreadPicName,uid,inviteCode,"2",new Long(0));

                    spreadUrl = apiUrl + "/api/file/qrcode/"+spreadPicName;
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }else{
                spreadUrl = apiUrl + "/api/file/" + attachmentT.getSattDir();
            }
        }
        else{//其他
            if(StrUtil.isBlank(from)) {
                from = AppFromEnum.H5.getValue();
            }

            String name = uid + "_"+from+"_user_wap.jpg";

            YxSystemAttachment attachment = systemAttachmentService.getInfo(name);
            String fileDir = path+"qrcode"+File.separator;
            String qrcodeUrl = "";
            String QrCode ="";
            String str ="scene=spread="+uid;
            String url ="pages/Loading/index";
            if(ObjectUtil.isNull(attachment)){
                //生成二维码
                //判断用户是否小程序,注意小程序二维码生成路径要与H5不一样 不然会导致都跳转到小程序问题
                if(from.equals(AppFromEnum.ROUNTINE.getValue())){
                    //siteUrl = siteUrl+"/distribution/";
                    getminiqrQr(str,fileDir,name,url);
                }else if(AppFromEnum.UNIAPPH5.getValue().equals(from)){
                    String uniUrl = systemConfigService.getData(SystemConfigConstants.UNI_SITE_URL);
                    siteUrl =  StrUtil.isNotBlank(uniUrl) ? uniUrl :  ShopConstants.DEFAULT_UNI_H5_URL;
                    siteUrl = siteUrl+"/pages/Loading/index";
                    QrCodeUtil.generate(siteUrl+"?spread="+uid, 180, 180,
                            FileUtil.file(fileDir+name));
                }else{
                    QrCodeUtil.generate(siteUrl+"?spread="+uid, 180, 180,
                            FileUtil.file(fileDir+name));
                }

                File file = FileUtil.mkdir(new File(fileDir));

                systemAttachmentService.attachmentAdd(name,String.valueOf(FileUtil.size(file)),
                        fileDir+name,"qrcode/"+name);

                qrcodeUrl = fileDir+name;
            }else{
                qrcodeUrl = attachment.getAttDir();
            }

            String spreadPicName = uid + "_"+from+"_user_spread.jpg";
            String spreadPicPath = fileDir+spreadPicName;

            YxSystemAttachment attachmentT = systemAttachmentService.getInfo(spreadPicName);
            if(ObjectUtil.isNull(attachmentT)){
                try {
                    /*URI url1 = new URI(wechatSpreadImg);
                    log.info("url1==============="+url1);
                    File file = new File(url1.toString());
                    log.info("file==============="+file);*/
                    Font font =  Font.createFont(Font.TRUETYPE_FONT, newFileT);
                    Font f= font.deriveFont(Font.PLAIN,30);
                    //font.
                    URL img1 =new URL(wechatSpreadImg);
                    log.info("url1==============="+img1);
                    int lastSlashIndex = wechatSpreadImg.lastIndexOf("/");
                    String fileImgDir = "/home/yshop/file/pic"+wechatSpreadImg.substring(lastSlashIndex);
                    String nickname =userInfo.getNickname();
                    if(nickname.length()>8){
                        nickname =nickname.substring(0,7)+"...";
                    }
                    ImgUtil.pressText(//
                            //ImgUtil.read(new URL(wechatSpreadImg)),
                            FileUtil.file(fileImgDir),
                            //newFile,
                            FileUtil.file(spreadPicPath),
                            nickname+"邀您加入",
                            Color.BLACK,
                            f, //字体
                            0, //x坐标修正值。 默认在中间，偏移量相对于中间偏移
                            520, //y坐标修正值。 默认在中间，偏移量相对于中间偏移
                            0.8f//透明度：alpha 必须是范围 [0.0, 1.0] 之内（包含边界值）的一个浮点数字
                    );
                    //微信头像图片
                    String headimgurl ="https://juxi.judouwh.top/file/static/avatar.jpg";
                    Image newImage = null;
                    /*if(ObjectUtil.isNotEmpty(userInfo.getAvatar())){
                        headimgurl =userInfo.getAvatar();
                        URL img =new URL(headimgurl);
                        BufferedImage image =ImageIO.read(img);
                        newImage = image.getScaledInstance(164, 164, Image.SCALE_DEFAULT);
                    }else{
                        if(ObjectUtil.isNotEmpty(userInfo.getWxProfile().getHeadimgurl())){
                            headimgurl =userInfo.getWxProfile().getHeadimgurl();
                            URL img =new URL(headimgurl);
                            BufferedImage image =ImageIO.read(img);
                            newImage = image.getScaledInstance(164, 164, Image.SCALE_DEFAULT);
                        }

                    }*/
                    if(ObjectUtil.isNotEmpty(userInfo.getAvatar())){
                        headimgurl =userInfo.getAvatar();
                        log.info("headimgurl==============="+headimgurl);
                        int lastHeadIndex = headimgurl.lastIndexOf("/");
                        String fileHeadImgDir = path+"pic"+headimgurl.substring(lastHeadIndex);
                        //URL img =new URL(headimgurl);
                        File file =FileUtil.file(fileHeadImgDir);
                        log.info("fileHeadImgDir==============="+fileHeadImgDir);
                        BufferedImage image =ImageIO.read(file);
                        //log.info("image==============="+image);
                        newImage = image.getScaledInstance(164, 164, Image.SCALE_DEFAULT);
                    }else{
                        if(ObjectUtil.isNotEmpty(userInfo.getWxProfile().getHeadimgurl())){
                            headimgurl =userInfo.getWxProfile().getHeadimgurl();
                            log.info("headimgurl1111==============="+headimgurl);
                            URL img =new URL(headimgurl);
                            log.info("img11111==============="+headimgurl);
                            BufferedImage image =ImageIO.read(img);
                            log.info("image1111==============="+image);
                            newImage = image.getScaledInstance(164, 164, Image.SCALE_DEFAULT);
                        }

                    }
                    ImgUtil.pressImage(//
                            FileUtil.file(spreadPicPath),
                            FileUtil.file(spreadPicPath),
                            newImage,
                            0, //x坐标修正值。 默认在中间，偏移量相对于中间偏移
                            420, //y坐标修正值。 默认在中间，偏移量相对于中间偏移
                            0.8f//透明度：alpha 必须是范围 [0.0, 1.0] 之内（包含边界值）的一个浮点数字
                    );


                    ImgUtil.pressImage(
                            FileUtil.file(spreadPicPath),
                            FileUtil.file(spreadPicPath),
                            ImgUtil.read(FileUtil.file(qrcodeUrl)), //水印图片
                            0, //x坐标修正值。 默认在中间，偏移量相对于中间偏移
                            173, //y坐标修正值。 默认在中间，偏移量相对于中间偏移
                            0.8f
                    );

                    systemAttachmentService.newAttachment4SpreadAdd(spreadPicName,
                            String.valueOf(FileUtil.size(new File(spreadPicPath))),
                            spreadPicPath,"qrcode/"+spreadPicName,uid,"","2",new Long(0));

                    spreadUrl = apiUrl + "/api/file/qrcode/"+spreadPicName;

                } catch (Exception e) {
                    e.printStackTrace();
                }
            }else{
                spreadUrl = apiUrl + "/api/file/" + attachmentT.getSattDir();
                log.info("spreadUrl111==============="+spreadUrl);
            }

        }
        log.info("结束===============");
        log.info("spreadUrl2222==============="+spreadUrl);
        return spreadUrl;
    }

    /**
     * 获取用户授权书url
     * @param from 来源
     * @param userInfo 用户
     * @param siteUrl h5地址
     * @param apiUrl api地址
     * @param path 本地图片路径
     * @return url
     */
    public String getAuthorizeUrl(String from,YxUser userInfo,String siteUrl,
                               String apiUrl,String path){
        String spreadUrl = "";
        Long uid = userInfo.getUid();
        log.info("开始===============");
        log.info("用户ID==============="+uid);
        String wechatAuthorizeImg =systemConfigService.getData(ShopConstants.WECHAT_AUTHORIZE_IMG);
        if(userInfo.getLevel()>3){
            wechatAuthorizeImg =systemConfigService.getData(ShopConstants.WECHAT_ASSOCIATES_IMG);
        }else if(userInfo.getLevel()>2){
            wechatAuthorizeImg =systemConfigService.getData(ShopConstants.WECHAT_OPERATOR_IMG);
        }
        //公章背景图
        String officialSealImg =systemConfigService.getData(ShopConstants.WECHAT_OFFICIAL_SEAL_IMG);
        //授权时间
        String effectiveTime =systemConfigService.getData(ShopConstants.AUTHORIZATION_EFFECTIVE_TIME);
        //File newFile = FileUtil.file("fx7.jpg");
        //log.info("newFile==============="+newFile);
        File newFileT = new File("simsunb.ttf");
        try {
            /*if(!newFile.exists()){
                InputStream stream =  getClass().getClassLoader().getResourceAsStream("fx.jpg");
                FileUtils.copyInputStreamToFile(stream, newFile);
            }*/
            if(!newFileT.exists()){
                InputStream streamT =  getClass().getClassLoader()
                        .getResourceAsStream("simsunb.ttf");
                FileUtils.copyInputStreamToFile(streamT, newFileT);
            }
        } catch (IOException e) {
            log.error(e.getMessage());
            throw new YshopException(e.getMessage());
        }

        if(StrUtil.isNotBlank(from) && AppFromEnum.APP.getValue().equals(from)){
            String spreadPicName = uid + "_"+from+"_user_authorize.jpg";
            if(userInfo.getLevel()>3){
                spreadPicName = uid + "_"+from+"_user_associates.jpg";
            }else if(userInfo.getLevel()>2){
                spreadPicName = uid + "_"+from+"_user_operator.jpg";
            }
            String fileDir = path+"qrcode"+File.separator;
            String spreadPicPath = fileDir+spreadPicName;

            YxSystemAttachment attachmentT = systemAttachmentService.getInfo(spreadPicName);
            log.info("attachmentT==============="+attachmentT);
            if(ObjectUtil.isNull(attachmentT)){
                try {
                    Font font =  Font.createFont(Font.TRUETYPE_FONT, newFileT);
                    Font f= font.deriveFont(Font.PLAIN,20);
                    ImgUtil.pressText(//
                            FileUtil.file(wechatAuthorizeImg),
                            //newFile,
                            FileUtil.file(spreadPicPath),
                            userInfo.getNickname()+"邀您加入",
                            Color.BLACK,
                            f, //字体
                            0, //x坐标修正值。 默认在中间，偏移量相对于中间偏移
                            300, //y坐标修正值。 默认在中间，偏移量相对于中间偏移
                            0.8f//透明度：alpha 必须是范围 [0.0, 1.0] 之内（包含边界值）的一个浮点数字
                    );

                    String inviteCode =  OrderUtil.createShareCode();
                    ImgUtil.pressText(
                            FileUtil.file(spreadPicPath),
                            FileUtil.file(spreadPicPath),
                            "邀您码:"+ inviteCode,
                            Color.RED,
                            f, //字体
                            0, //x坐标修正值。 默认在中间，偏移量相对于中间偏移
                            340, //y坐标修正值。 默认在中间，偏移量相对于中间偏移
                            0.8f
                    );

                    systemAttachmentService.newAttachment4SpreadAdd(spreadPicName,
                            String.valueOf(FileUtil.size(new File(spreadPicPath))),
                            spreadPicPath,"qrcode/"+spreadPicName,uid,inviteCode,"5",new Long(0));

                    spreadUrl = apiUrl + "/api/file/qrcode/"+spreadPicName;
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }else{
                spreadUrl = apiUrl + "/api/file/" + attachmentT.getSattDir();
            }
        }
        else{//其他
            if(StrUtil.isBlank(from)) {
                from = AppFromEnum.H5.getValue();
            }

            /*String name = uid + "_"+from+"_user_wap.jpg";

            YxSystemAttachment attachment = systemAttachmentService.getInfo(name);*/
            String fileDir = path+"qrcode"+File.separator;


            String spreadPicName = uid + "_"+from+"_user_authorize.jpg";
            if(userInfo.getLevel()>3){
                spreadPicName = uid + "_"+from+"_user_associates.jpg";
            }else if(userInfo.getLevel()>2){
                spreadPicName = uid + "_"+from+"_user_operator.jpg";
            }
            String spreadPicPath = fileDir+spreadPicName;

            YxSystemAttachment attachmentT = systemAttachmentService.getInfo(spreadPicName);
            if(ObjectUtil.isNull(attachmentT)){
                try {
                    /*URI url1 = new URI(wechatSpreadImg);
                    log.info("url1==============="+url1);
                    File file = new File(url1.toString());
                    log.info("file==============="+file);*/
                    Font font =  Font.createFont(Font.TRUETYPE_FONT, newFileT);
                    Font f= font.deriveFont(Font.PLAIN,60);
                    //font.
                    String nickname =userInfo.getBankUserName();
                    Calendar now = Calendar.getInstance();
                    Calendar current =now;
                    long time1 = current.getTimeInMillis();
                    YxUser user =yxUserService.getById(uid);
                    user.setWhetherAuthorize("Y");
                    user.setAuthBeginDate(current.getTime());
                    int year = now.get(Calendar.YEAR);
                    int month =now.get(Calendar.MONTH) + 1;
                    int day =now.get(Calendar.DAY_OF_MONTH);
                    now.add(Calendar.YEAR, Integer.valueOf(effectiveTime));
                    Calendar nextYear =now;
                    int nextOfYear = nextYear.get(Calendar.YEAR);
                    int nextOfMonth =nextYear.get(Calendar.MONTH) + 1;
                    int nextOfDay =nextYear.get(Calendar.DAY_OF_MONTH);
                    /*if(nickname.length()>8){
                        nickname =nickname.substring(0,7)+"...";
                    }*/
                    //名称
                    ImgUtil.pressText(//
                            ImgUtil.read(new URL(wechatAuthorizeImg)),
                            //newFile,
                            FileUtil.file(spreadPicPath),
                            nickname,
                            Color.BLACK,
                            f, //字体
                            -50, //x坐标修正值。 默认在中间，偏移量相对于中间偏移
                            -240, //y坐标修正值。 默认在中间，偏移量相对于中间偏移
                            0.8f//透明度：alpha 必须是范围 [0.0, 1.0] 之内（包含边界值）的一个浮点数字
                    );
                    if(userInfo.getLevel()==2){
                        //当前年份
                        ImgUtil.pressText(//
                                FileUtil.file(spreadPicPath),
                                //newFile,
                                FileUtil.file(spreadPicPath),
                                String.valueOf(year),
                                Color.BLACK,
                                f, //字体
                                -480, //x坐标修正值。 默认在中间，偏移量相对于中间偏移
                                -70, //y坐标修正值。 默认在中间，偏移量相对于中间偏移
                                0.8f//透明度：alpha 必须是范围 [0.0, 1.0] 之内（包含边界值）的一个浮点数字
                        );
                        //当前月份
                        ImgUtil.pressText(//
                                FileUtil.file(spreadPicPath),
                                //newFile,
                                FileUtil.file(spreadPicPath),
                                String.valueOf(month),
                                Color.BLACK,
                                f, //字体
                                -250, //x坐标修正值。 默认在中间，偏移量相对于中间偏移
                                -70, //y坐标修正值。 默认在中间，偏移量相对于中间偏移
                                0.8f//透明度：alpha 必须是范围 [0.0, 1.0] 之内（包含边界值）的一个浮点数字
                        );
                    }else if(userInfo.getLevel()==3){
                        //当前年份
                        ImgUtil.pressText(//
                                FileUtil.file(spreadPicPath),
                                //newFile,
                                FileUtil.file(spreadPicPath),
                                String.valueOf(year),
                                Color.BLACK,
                                f, //字体
                                -410, //x坐标修正值。 默认在中间，偏移量相对于中间偏移
                                -70, //y坐标修正值。 默认在中间，偏移量相对于中间偏移
                                0.8f//透明度：alpha 必须是范围 [0.0, 1.0] 之内（包含边界值）的一个浮点数字
                        );
                        //当前月份
                        ImgUtil.pressText(//
                                FileUtil.file(spreadPicPath),
                                //newFile,
                                FileUtil.file(spreadPicPath),
                                String.valueOf(month),
                                Color.BLACK,
                                f, //字体
                                -180, //x坐标修正值。 默认在中间，偏移量相对于中间偏移
                                -70, //y坐标修正值。 默认在中间，偏移量相对于中间偏移
                                0.8f//透明度：alpha 必须是范围 [0.0, 1.0] 之内（包含边界值）的一个浮点数字
                        );
                    }else if(userInfo.getLevel()==4){
                        //当前年份
                        ImgUtil.pressText(//
                                FileUtil.file(spreadPicPath),
                                //newFile,
                                FileUtil.file(spreadPicPath),
                                String.valueOf(year),
                                Color.BLACK,
                                f, //字体
                                -560, //x坐标修正值。 默认在中间，偏移量相对于中间偏移
                                -70, //y坐标修正值。 默认在中间，偏移量相对于中间偏移
                                0.8f//透明度：alpha 必须是范围 [0.0, 1.0] 之内（包含边界值）的一个浮点数字
                        );
                        //当前月份
                        ImgUtil.pressText(//
                                FileUtil.file(spreadPicPath),
                                //newFile,
                                FileUtil.file(spreadPicPath),
                                String.valueOf(month),
                                Color.BLACK,
                                f, //字体
                                -330, //x坐标修正值。 默认在中间，偏移量相对于中间偏移
                                -70, //y坐标修正值。 默认在中间，偏移量相对于中间偏移
                                0.8f//透明度：alpha 必须是范围 [0.0, 1.0] 之内（包含边界值）的一个浮点数字
                        );
                    }

                    /*//手机号码
                    ImgUtil.pressText(//
                            FileUtil.file(spreadPicPath),
                            //newFile,
                            FileUtil.file(spreadPicPath),
                            userInfo.getPhone(),
                            Color.BLACK,
                            f, //字体
                            -730, //x坐标修正值。 默认在中间，偏移量相对于中间偏移
                            360, //y坐标修正值。 默认在中间，偏移量相对于中间偏移
                            0.8f//透明度：alpha 必须是范围 [0.0, 1.0] 之内（包含边界值）的一个浮点数字
                    );
                    //身份证
                    ImgUtil.pressText(//
                            FileUtil.file(spreadPicPath),
                            //newFile,
                            FileUtil.file(spreadPicPath),
                            userInfo.getCardId(),
                            Color.BLACK,
                            f, //字体
                            -550, //x坐标修正值。 默认在中间，偏移量相对于中间偏移
                            440, //y坐标修正值。 默认在中间，偏移量相对于中间偏移
                            0.8f//透明度：alpha 必须是范围 [0.0, 1.0] 之内（包含边界值）的一个浮点数字
                    );*/
                    /*//授权人
                    ImgUtil.pressText(//
                            FileUtil.file(spreadPicPath),
                            //newFile,
                            FileUtil.file(spreadPicPath),
                            nickname,
                            Color.BLACK,
                            f, //字体
                            -400, //x坐标修正值。 默认在中间，偏移量相对于中间偏移
                            -110, //y坐标修正值。 默认在中间，偏移量相对于中间偏移
                            0.8f//透明度：alpha 必须是范围 [0.0, 1.0] 之内（包含边界值）的一个浮点数字
                    );
                    */

                    //公章
                    ImgUtil.pressImage(//
                            FileUtil.file(spreadPicPath),
                            FileUtil.file(spreadPicPath),
                            ImgUtil.read(new URL(officialSealImg)),
                            480, //x坐标修正值。 默认在中间，偏移量相对于中间偏移
                            900, //y坐标修正值。 默认在中间，偏移量相对于中间偏移
                            0.8f//透明度：alpha 必须是范围 [0.0, 1.0] 之内（包含边界值）的一个浮点数字
                    );
                    long time2 = nextYear.getTimeInMillis();
                    long between_days=(time2-time1)/(1000*3600*24);
                    //传入redis的天数
                    int days =Integer.parseInt(String.valueOf(between_days));
                    //int days =Integer.parseInt(String.valueOf(1));

                    user.setAuthEndDate(nextYear.getTime());
                    yxUserService.updateById(user);
                    //加入redis，day天后自动取消授权
                    String redisKey = String.valueOf(StrUtil.format("{}{}",
                            ShopConstants.REDIS_AUTHORIZATION,user.getUid()));
                    redisTemplate.opsForValue().set(redisKey, user.getUid().toString(),
                            Long.valueOf(days), TimeUnit.DAYS);
                    //当前年份
                    ImgUtil.pressText(//
                            FileUtil.file(spreadPicPath),
                            //newFile,
                            FileUtil.file(spreadPicPath),
                            String.valueOf(year),
                            Color.BLACK,
                            f, //字体
                            -130, //x坐标修正值。 默认在中间，偏移量相对于中间偏移
                            875, //y坐标修正值。 默认在中间，偏移量相对于中间偏移
                            0.8f//透明度：alpha 必须是范围 [0.0, 1.0] 之内（包含边界值）的一个浮点数字
                    );
                    //当前月份
                    ImgUtil.pressText(//
                            FileUtil.file(spreadPicPath),
                            //newFile,
                            FileUtil.file(spreadPicPath),
                            String.valueOf(month),
                            Color.BLACK,
                            f, //字体
                            70, //x坐标修正值。 默认在中间，偏移量相对于中间偏移
                            875, //y坐标修正值。 默认在中间，偏移量相对于中间偏移
                            0.8f//透明度：alpha 必须是范围 [0.0, 1.0] 之内（包含边界值）的一个浮点数字
                    );
                    //当前日
                    ImgUtil.pressText(//
                            FileUtil.file(spreadPicPath),
                            //newFile,
                            FileUtil.file(spreadPicPath),
                            String.valueOf(day),
                            Color.BLACK,
                            f, //字体
                            220, //x坐标修正值。 默认在中间，偏移量相对于中间偏移
                            875, //y坐标修正值。 默认在中间，偏移量相对于中间偏移
                            0.8f//透明度：alpha 必须是范围 [0.0, 1.0] 之内（包含边界值）的一个浮点数字
                    );

                    //截止年份
                    ImgUtil.pressText(//
                            FileUtil.file(spreadPicPath),
                            //newFile,
                            FileUtil.file(spreadPicPath),
                            String.valueOf(nextOfYear),
                            Color.BLACK,
                            f, //字体
                            470, //x坐标修正值。 默认在中间，偏移量相对于中间偏移
                            875, //y坐标修正值。 默认在中间，偏移量相对于中间偏移
                            0.8f//透明度：alpha 必须是范围 [0.0, 1.0] 之内（包含边界值）的一个浮点数字
                    );
                    //截止月份
                    ImgUtil.pressText(//
                            FileUtil.file(spreadPicPath),
                            //newFile,
                            FileUtil.file(spreadPicPath),
                            String.valueOf(nextOfMonth),
                            Color.BLACK,
                            f, //字体
                            670, //x坐标修正值。 默认在中间，偏移量相对于中间偏移
                            875, //y坐标修正值。 默认在中间，偏移量相对于中间偏移
                            0.8f//透明度：alpha 必须是范围 [0.0, 1.0] 之内（包含边界值）的一个浮点数字
                    );
                    //截止日
                    ImgUtil.pressText(//
                            FileUtil.file(spreadPicPath),
                            //newFile,
                            FileUtil.file(spreadPicPath),
                            String.valueOf(nextOfDay),
                            Color.BLACK,
                            f, //字体
                            830, //x坐标修正值。 默认在中间，偏移量相对于中间偏移
                            875, //y坐标修正值。 默认在中间，偏移量相对于中间偏移
                            0.8f//透明度：alpha 必须是范围 [0.0, 1.0] 之内（包含边界值）的一个浮点数字
                    );
                    //微信头像图片
                    /*String headimgurl ="https://h5.ylsp.vip/file/static/avatar.jpg";
                    if(ObjectUtil.isNotEmpty(userInfo.getWxProfile().getHeadimgurl())){
                        headimgurl =userInfo.getWxProfile().getHeadimgurl();
                    }
                    ImgUtil.pressImage(//
                            FileUtil.file(spreadPicPath),
                            FileUtil.file(spreadPicPath),
                            ImgUtil.read(new URL(headimgurl)),
                            0, //x坐标修正值。 默认在中间，偏移量相对于中间偏移
                            420, //y坐标修正值。 默认在中间，偏移量相对于中间偏移
                            0.8f//透明度：alpha 必须是范围 [0.0, 1.0] 之内（包含边界值）的一个浮点数字
                    );*/

                    systemAttachmentService.newAttachment4SpreadAdd(spreadPicName,
                            String.valueOf(FileUtil.size(new File(spreadPicPath))),
                            spreadPicPath,"qrcode/"+spreadPicName,uid,"","5",user.getUid());

                    spreadUrl = apiUrl + "/api/file/qrcode/"+spreadPicName;

                } catch (Exception e) {
                    e.printStackTrace();
                }
            }else{
                spreadUrl = apiUrl + "/api/file/" + attachmentT.getSattDir();
                log.info("spreadUrl111==============="+spreadUrl);
            }

        }
        log.info("结束===============");
        log.info("spreadUrl2222==============="+spreadUrl);
        return spreadUrl;
    }

    /**
     * 获取直播间二维码url
     * @param from 来源
     * @param userInfo 用户
     * @param siteUrl h5地址
     * @param apiUrl api地址
     * @param path 本地图片路径
     * @return url
     */
    public String getSpreadLiveUrl(String from,YxUser userInfo,String siteUrl,
                               String apiUrl,String path,String roomId,String coverImge){
        String spreadUrl = "";
        Long uid = userInfo.getUid();
        log.info("开始===============");
        log.info("用户ID==============="+uid);
        //File newFile = new File("live6.jpg");
        File newFileT = new File("simsunb.ttf");
        try {
            /*if(!newFile.exists()){
                InputStream stream =  getClass().getClassLoader().getResourceAsStream("live.jpg");
                FileUtils.copyInputStreamToFile(stream, newFile);
            }*/
            if(!newFileT.exists()){
                InputStream streamT =  getClass().getClassLoader()
                        .getResourceAsStream("simsunb.ttf");
                FileUtils.copyInputStreamToFile(streamT, newFileT);
            }
        } catch (IOException e) {
            log.error(e.getMessage());
            throw new YshopException(e.getMessage());
        }

        if(StrUtil.isNotBlank(from) && AppFromEnum.APP.getValue().equals(from)){
            String spreadPicName = roomId+"_"+uid + "_"+from+"_live_spread.jpg";
            String fileDir = path+"qrcode"+File.separator;
            String spreadPicPath = fileDir+spreadPicName;

            YxSystemAttachment attachmentT = systemAttachmentService.getInfo(spreadPicName);
            log.info("attachmentT==============="+attachmentT);
            if(ObjectUtil.isNull(attachmentT)){
                try {
                    Font font =  Font.createFont(Font.TRUETYPE_FONT, newFileT);
                    Font f= font.deriveFont(Font.PLAIN,20);
                    ImgUtil.pressText(//
                            //newFile,
                            ImgUtil.read(new URL(coverImge)),
                            FileUtil.file(spreadPicPath),
                            userInfo.getNickname()+"邀您加入",
                            Color.BLACK,
                            f, //字体
                            0, //x坐标修正值。 默认在中间，偏移量相对于中间偏移
                            300, //y坐标修正值。 默认在中间，偏移量相对于中间偏移
                            0.8f//透明度：alpha 必须是范围 [0.0, 1.0] 之内（包含边界值）的一个浮点数字
                    );

                    String inviteCode =  OrderUtil.createShareCode();
                    ImgUtil.pressText(
                            FileUtil.file(spreadPicPath),
                            FileUtil.file(spreadPicPath),
                            "邀您码:"+ inviteCode,
                            Color.RED,
                            f, //字体
                            0, //x坐标修正值。 默认在中间，偏移量相对于中间偏移
                            340, //y坐标修正值。 默认在中间，偏移量相对于中间偏移
                            0.8f
                    );

                    systemAttachmentService.newAttachmentAdd(spreadPicName,
                            String.valueOf(FileUtil.size(new File(spreadPicPath))),
                            spreadPicPath,"qrcode/"+spreadPicName,uid,inviteCode);

                    spreadUrl = apiUrl + "/api/file/qrcode/"+spreadPicName;
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }else{
                spreadUrl = apiUrl + "/api/file/" + attachmentT.getSattDir();
            }
        }
        else{//其他
            if(StrUtil.isBlank(from)) {
                from = AppFromEnum.H5.getValue();
            }

            String name = roomId+"_"+uid + "_"+from+"_live_wap.jpg";

            YxSystemAttachment attachment = systemAttachmentService.getInfo(name);
            String fileDir = path+"qrcode"+File.separator;
            String qrcodeUrl = "";
            String QrCode ="";
            String str ="spread="+uid+"-roomId="+roomId;
            String url ="pages/LivePosters/LivePoster";
            if(ObjectUtil.isNull(attachment)){
                //生成二维码
                //判断用户是否小程序,注意小程序二维码生成路径要与H5不一样 不然会导致都跳转到小程序问题
                if(from.equals(AppFromEnum.ROUNTINE.getValue())){
                    //siteUrl = siteUrl+"/distribution/";
                    getminiqrQr(str,fileDir,name,url);
                }else if(AppFromEnum.UNIAPPH5.getValue().equals(from)){
                    String uniUrl = systemConfigService.getData(SystemConfigConstants.UNI_SITE_URL);
                    siteUrl =  StrUtil.isNotBlank(uniUrl) ? uniUrl :  ShopConstants.DEFAULT_UNI_H5_URL;
                    siteUrl = siteUrl+"/pages/LivePosters/LivePoster";
                    QrCodeUtil.generate(siteUrl+"?spread="+uid, 180, 180,
                            FileUtil.file(fileDir+name));
                }else{
                    QrCodeUtil.generate(siteUrl+"?spread="+uid, 180, 180,
                            FileUtil.file(fileDir+name));
                }

                File file = FileUtil.mkdir(new File(fileDir));

                systemAttachmentService.attachmentAdd(name,String.valueOf(FileUtil.size(file)),
                        fileDir+name,"qrcode/"+name);

                qrcodeUrl = fileDir+name;
            }else{
                qrcodeUrl = attachment.getAttDir();
            }

            String spreadPicName = roomId+"_"+uid + "_"+from+"_live_spread.jpg";
            String spreadPicPath = fileDir+spreadPicName;

            YxSystemAttachment attachmentT = systemAttachmentService.getInfo(spreadPicName);
            if(ObjectUtil.isNull(attachmentT)){
                try {

                    Font font =  Font.createFont(Font.TRUETYPE_FONT, newFileT);
                    Font f= font.deriveFont(Font.PLAIN,30);
                    //font.
                    String nickname =userInfo.getNickname();
                    if(nickname.length()>8){
                        nickname =nickname.substring(0,7)+"...";
                    }
                    ImgUtil.pressText(//
                            //newFile,
                            ImgUtil.read(new URL(coverImge)),
                            FileUtil.file(spreadPicPath),
                            nickname+"邀您加入",
                            Color.BLACK,
                            f, //字体
                            0, //x坐标修正值。 默认在中间，偏移量相对于中间偏移
                            520, //y坐标修正值。 默认在中间，偏移量相对于中间偏移
                            0.8f//透明度：alpha 必须是范围 [0.0, 1.0] 之内（包含边界值）的一个浮点数字
                    );
                    //微信头像图片
                    String headimgurl ="https://h5.ylsp.vip/file/static/avatar.jpg";
                    if(ObjectUtil.isNotEmpty(userInfo.getWxProfile().getHeadimgurl())){
                        headimgurl =userInfo.getWxProfile().getHeadimgurl();
                    }
                    ImgUtil.pressImage(//
                            FileUtil.file(spreadPicPath),
                            FileUtil.file(spreadPicPath),
                            ImgUtil.read(new URL(headimgurl)),
                            0, //x坐标修正值。 默认在中间，偏移量相对于中间偏移
                            420, //y坐标修正值。 默认在中间，偏移量相对于中间偏移
                            0.8f//透明度：alpha 必须是范围 [0.0, 1.0] 之内（包含边界值）的一个浮点数字
                    );


                    ImgUtil.pressImage(
                            FileUtil.file(spreadPicPath),
                            FileUtil.file(spreadPicPath),
                            ImgUtil.read(FileUtil.file(qrcodeUrl)), //水印图片
                            0, //x坐标修正值。 默认在中间，偏移量相对于中间偏移
                            173, //y坐标修正值。 默认在中间，偏移量相对于中间偏移
                            0.8f
                    );

                    systemAttachmentService.attachmentAdd(spreadPicName,
                            String.valueOf(FileUtil.size(new File(spreadPicPath))),
                            spreadPicPath,"qrcode/"+spreadPicName);

                    spreadUrl = apiUrl + "/api/file/qrcode/"+spreadPicName;

                } catch (Exception e) {
                    e.printStackTrace();
                }
            }else{
                spreadUrl = apiUrl + "/api/file/" + attachmentT.getSattDir();
                log.info("spreadUrl11==============="+spreadUrl);
            }

        }
        log.info("结束===============");
        log.info("spreadUrl2222==============="+spreadUrl);
        return spreadUrl;
    }


    /**
     * 获取砍价海报
     * @param bargainId 砍价商品id
     * @param userInfo 用户
     * @param siteUrl h5地址
     * @param apiUrl api地址
     * @param path 本地图片路径
     * @return url
     */
    public String getBargainPosterUrl(Long bargainId, YxUser userInfo,String siteUrl,
                                      String apiUrl,String path,String from){
        Long uid = userInfo.getUid();
        YxStoreBargain storeBargainQueryVo = storeBargainService
                .getById(bargainId);
        YxStoreBargainUser storeBargainUser = storeBargainUserService
                .getBargainUserInfo(bargainId,uid);

        if(ObjectUtil.isNull(storeBargainQueryVo) || ObjectUtil.isNull(storeBargainUser)) {
            throw new YshopException("数据不存在");
        }
        //用户可以砍掉的金额 好友砍价之前获取可以砍价金额
        double coverPrice = NumberUtil.sub(storeBargainUser.getBargainPrice()
                ,storeBargainUser.getBargainPriceMin()).doubleValue();
        //用户剩余要砍掉的价格
        double surplusPrice = NumberUtil.sub(coverPrice,
                storeBargainUser.getPrice()).doubleValue();


        String name = bargainId+"_"+uid + "_"+from+"_bargain_share_wap.jpg";
        YxSystemAttachment attachment = systemAttachmentService.getInfo(name);
        //删除已经存在的砍价海报图片
        if (ObjectUtil.isNotNull(attachment)) {
            storeBargainService.deleteBargainImg(name);
        }
        String fileDir = path+"qrcode"+ File.separator;
        String qrcodeUrl = "";
        if(ObjectUtil.isNull(attachment)){
            //生成二维码
            //判断用户是否小程序,注意小程序二维码生成路径要与H5不一样 不然会导致都跳转到小程序问题
            File file = FileUtil.mkdir(new File(fileDir));
            if(AppFromEnum.ROUNTINE.getValue().equals(from)){
                siteUrl = siteUrl+"/bargain/";
                QrCodeUtil.generate(siteUrl+"?bargainId="+bargainId+"&uid="+uid+"&partake="+uid+"&pageType=dargain&codeType="+AppFromEnum.ROUNTINE.getValue(), 180, 180,
                        FileUtil.file(fileDir+name));
            }
            else if(AppFromEnum.APP.getValue().equals(from)){
                siteUrl = siteUrl+"/bargain/";
                QrCodeUtil.generate(siteUrl+"?bargainId="+bargainId+"&uid="+uid+"&partake="+uid+"&pageType=dargain&codeType="+AppFromEnum.APP.getValue(), 180, 180,
                        FileUtil.file(fileDir+name));
            }else if(AppFromEnum.H5.getValue().equals(from)){
                QrCodeUtil.generate(siteUrl+"/activity/dargain_detail/"+bargainId+"/"+uid+"?spread="+uid, 180, 180,
                        FileUtil.file(fileDir+name));
            }else {
                String uniUrl = systemConfigService.getData(SystemConfigConstants.UNI_SITE_URL);
                siteUrl =  StrUtil.isNotBlank(uniUrl) ? uniUrl :  ShopConstants.DEFAULT_UNI_H5_URL;
                QrCodeUtil.generate(siteUrl+"/pages/activity/DargainDetails/index?id="+bargainId+"&uid="+uid+"&partake="+uid, 180, 180,
                        FileUtil.file(fileDir+name));
            }
            systemAttachmentService.attachmentAdd(name,String.valueOf(FileUtil.size(file)),
                    fileDir+name,"qrcode/"+name);
            qrcodeUrl = fileDir+name;
        }else{
            qrcodeUrl = attachment.getAttDir();
        }

        String spreadPicName = bargainId+"_"+uid + "_"+from+"_bargain_user_spread.jpg";
        String spreadPicPath = fileDir+spreadPicName;

        YxSystemAttachment attachmentT = systemAttachmentService.getInfo(spreadPicName);
        //删除已经存在的砍价海报图片
        if (ObjectUtil.isNotNull(attachmentT)) {
            storeBargainService.deleteBargainImg(spreadPicName);
        }
        String spreadUrl = "";
        File newFile = new File("poster.jpg");
        File newFileT = new File("simsunb.ttf");
        try {
            if(!newFile.exists()){
                InputStream stream =  getClass().getClassLoader().getResourceAsStream("poster.jpg");
                FileUtils.copyInputStreamToFile(stream, newFile);
            }
            if(!newFileT.exists()){
                InputStream streamT =  getClass().getClassLoader()
                        .getResourceAsStream("simsunb.ttf");
                FileUtils.copyInputStreamToFile(streamT, newFileT);
            }
        } catch (IOException e) {
            log.error(e.getMessage());
            throw new YshopException(e.getMessage());
        }
        if(ObjectUtil.isNull(attachmentT)){
            try {

                //第一步标题
                Font font =  Font.createFont(Font.TRUETYPE_FONT, newFileT);
                Font f= font.deriveFont(Font.PLAIN,30);
                //font.
                ImgUtil.pressText(//
                        newFile,
                        FileUtil.file(spreadPicPath),
                        storeBargainQueryVo.getTitle(),
                        Color.BLACK,
                        f, //字体
                        0, //x坐标修正值。 默认在中间，偏移量相对于中间偏移
                        -480, //y坐标修正值。 默认在中间，偏移量相对于中间偏移
                        0.8f//透明度：alpha 必须是范围 [0.0, 1.0] 之内（包含边界值）的一个浮点数字
                );
                Font f2= font.deriveFont(Font.PLAIN,45);
                //第2步价格
                ImgUtil.pressText(//
                        FileUtil.file(spreadPicPath),
                        FileUtil.file(spreadPicPath),
                        NumberUtil.sub(storeBargainQueryVo.getPrice(),
                                storeBargainUser.getPrice()).toString(),
                        Color.RED,
                        f2, //字体
                        -160, //x坐标修正值。 默认在中间，偏移量相对于中间偏移
                        -380, //y坐标修正值。 默认在中间，偏移量相对于中间偏移
                        0.8f//透明度：alpha 必须是范围 [0.0, 1.0] 之内（包含边界值）的一个浮点数字
                );

                Font f3= font.deriveFont(Font.PLAIN,30);

                ImgUtil.pressText(//
                        FileUtil.file(spreadPicPath),
                        FileUtil.file(spreadPicPath),
                        "已砍至",
                        Color.WHITE,
                        f3, //字体
                        90, //x坐标修正值。 默认在中间，偏移量相对于中间偏移
                        -385, //y坐标修正值。 默认在中间，偏移量相对于中间偏移
                        0.8f//透明度：alpha 必须是范围 [0.0, 1.0] 之内（包含边界值）的一个浮点数字
                );

                //第4步介绍
                String pro = "还差还差" + surplusPrice + "即可砍价成功";
                ImgUtil.pressText(//
                        FileUtil.file(spreadPicPath),
                        FileUtil.file(spreadPicPath),
                        pro,
                        Color.BLACK,
                        f3, //字体
                        -50, //x坐标修正值。 默认在中间，偏移量相对于中间偏移
                        -300, //y坐标修正值。 默认在中间，偏移量相对于中间偏移
                        0.8f//透明度：alpha 必须是范围 [0.0, 1.0] 之内（包含边界值）的一个浮点数字
                );

                //第5步商品图片
                //下载图片
                String image = storeBargainQueryVo.getImage();
                String ext = image.substring(image.lastIndexOf("."));
                String picImage = fileDir + "bargain_product_" + bargainId + ext;
                if(!new File(picImage).exists()){
                    //下载商品图
                    HttpUtil.downloadFile(image, FileUtil.file(picImage));
                    //只缩放一次防止图片持续缩放导致图片没了
                    ImgUtil.scale(
                            FileUtil.file(picImage),
                            FileUtil.file(picImage),
                            0.4f//缩放比例
                    );
                }

                ImgUtil.pressImage(
                        FileUtil.file(spreadPicPath),
                        FileUtil.file(spreadPicPath),
                        ImgUtil.read(FileUtil.file(picImage)), //水印图片
                        0, //x坐标修正值。 默认在中间，偏移量相对于中间偏移
                        -80, //y坐标修正值。 默认在中间，偏移量相对于中间偏移
                        0.7f
                );

                ImgUtil.pressImage(
                        FileUtil.file(spreadPicPath),
                        FileUtil.file(spreadPicPath),
                        ImgUtil.read(FileUtil.file(qrcodeUrl)), //水印图片
                        0, //x坐标修正值。 默认在中间，偏移量相对于中间偏移
                        390, //y坐标修正值。 默认在中间，偏移量相对于中间偏移
                        0.8f
                );

                systemAttachmentService.attachmentAdd(spreadPicName,
                        String.valueOf(FileUtil.size(new File(spreadPicPath))),
                        spreadPicPath,"qrcode/"+spreadPicName);

                spreadUrl = apiUrl + "/api/file/qrcode/"+spreadPicName;
            } catch (Exception e) {
                e.printStackTrace();
                log.error(e.getMessage());
                throw new YshopException("生成失败");
            }
        }else{
            spreadUrl = apiUrl + "/api/file/" + attachmentT.getSattDir();
        }

        return  spreadUrl;
    }


    /**
     * 获取拼团海报
     * @param pinkId 拼团id
     * @param userInfo 用户
     * @param siteUrl h5地址
     * @param apiUrl api地址
     * @param path 本地图片路径
     * @return url
     */
    public String getPinkPosterUrl(Long pinkId, YxUser userInfo,String siteUrl,
                                      String apiUrl,String path,String from){
        Long uid = userInfo.getUid();
        YxStorePink storePink = storePinkService.getById(pinkId);
        if(ObjectUtil.isNull(storePink)) {
            throw new YshopException("拼团不存在");
        }
        YxStoreCombination storeCombination = storeCombinationService.getById(storePink.getCid());
        if(ObjectUtil.isNull(storeCombination)) {
            throw new YshopException("拼团产品不存在");
        }

        String name = pinkId+"_"+uid + "_"+from+"_pink_share_wap.jpg";
        YxSystemAttachment attachment = systemAttachmentService.getInfo(name);
        String fileDir = path+"qrcode"+ File.separator;
        String qrcodeUrl = "";
        String str ="pinkId="+pinkId+"-spread="+uid+"-pageType=good";
        String url ="pages/Loading/index";
        if(ObjectUtil.isNull(attachment)){
            //生成二维码
            File file = FileUtil.mkdir(new File(fileDir));
            if(AppFromEnum.ROUNTINE.getValue().equals(from)){
                /*siteUrl = siteUrl+"/pink/";
                QrCodeUtil.generate(siteUrl+"?pinkId="+pinkId+"&spread="+uid+"&pageType=group&codeType="+AppFromEnum.ROUNTINE.getValue(), 180, 180,
                        FileUtil.file(fileDir+name));*/
                getminiqrQr(str,fileDir,name,url);
            }
            else if(AppFromEnum.APP.getValue().equals(from)){
                siteUrl = siteUrl+"/pink/";
                QrCodeUtil.generate(siteUrl+"?pinkId="+pinkId+"&spread="+uid+"&pageType=group&codeType="+AppFromEnum.ROUNTINE.getValue(), 180, 180,
                        FileUtil.file(fileDir+name));
            }
            else if(AppFromEnum.H5.getValue().equals(from)){
                QrCodeUtil.generate(siteUrl+"/activity/group_rule/"+pinkId+"?spread="+uid, 180, 180,
                        FileUtil.file(fileDir+name));
            }else {
                String uniUrl = systemConfigService.getData(SystemConfigConstants.UNI_SITE_URL);
                siteUrl =  StrUtil.isNotBlank(uniUrl) ? uniUrl :  ShopConstants.DEFAULT_UNI_H5_URL;
                QrCodeUtil.generate(siteUrl+"/pages/activity/GroupRule/index?id="+pinkId+"&spread="+uid, 180, 180,
                        FileUtil.file(fileDir+name));
            }


            systemAttachmentService.attachmentAdd(name,String.valueOf(FileUtil.size(file)),
                    fileDir+name,"qrcode/"+name);

            qrcodeUrl = fileDir+name;
        }else{
            qrcodeUrl = attachment.getAttDir();
        }

        String spreadPicName = pinkId+"_"+uid + "_"+from+"_pink_user_spread.jpg";
        String spreadPicPath = fileDir+spreadPicName;

        YxSystemAttachment attachmentT = systemAttachmentService.getInfo(spreadPicName);
        String spreadUrl = "";
//        InputStream stream =  getClass().getClassLoader().getResourceAsStream("poster.jpg");
//        InputStream streamT =  getClass().getClassLoader()
//                .getResourceAsStream("simsunb.ttf");
        File newFile = new File("poster.jpg");
        File newFileT = new File("simsunb.ttf");
        try {
            if(!newFileT.exists()){
                InputStream streamT =  getClass().getClassLoader()
                        .getResourceAsStream("simsunb.ttf");
                FileUtils.copyInputStreamToFile(streamT, newFileT);
            }
            if(!newFile.exists()){
                InputStream stream =  getClass().getClassLoader().getResourceAsStream("poster.jpg");
                FileUtils.copyInputStreamToFile(stream, newFile);
            }

        } catch (IOException e) {
            log.error(e.getMessage());
            throw new YshopException(e.getMessage());
        }
        if(ObjectUtil.isNull(attachmentT)){
            try {

                //第一步标题
                Font font =  Font.createFont(Font.TRUETYPE_FONT, newFileT);
                Font f= font.deriveFont(Font.PLAIN,40);
                //font.
                ImgUtil.pressText(//
                        newFile,
                        FileUtil.file(spreadPicPath),
                        storeCombination.getTitle(),
                        Color.BLACK,
                        f, //字体
                        0, //x坐标修正值。 默认在中间，偏移量相对于中间偏移
                        -480, //y坐标修正值。 默认在中间，偏移量相对于中间偏移
                        0.8f//透明度：alpha 必须是范围 [0.0, 1.0] 之内（包含边界值）的一个浮点数字
                );

                Font f2= font.deriveFont(Font.PLAIN,45);
                //第2步价格
                ImgUtil.pressText(//
                        FileUtil.file(spreadPicPath),
                        FileUtil.file(spreadPicPath),
                        storePink.getTotalPrice().toString(),
                        Color.RED,
                        f2, //字体
                        -160, //x坐标修正值。 默认在中间，偏移量相对于中间偏移
                        -380, //y坐标修正值。 默认在中间，偏移量相对于中间偏移
                        0.8f//透明度：alpha 必须是范围 [0.0, 1.0] 之内（包含边界值）的一个浮点数字
                );

                Font f3= font.deriveFont(Font.PLAIN,30);
                //第3步几人团
                ImgUtil.pressText(//
                        FileUtil.file(spreadPicPath),
                        FileUtil.file(spreadPicPath),
                        storePink.getPeople()+"人团",
                        Color.WHITE,
                        f3, //字体
                        90, //x坐标修正值。 默认在中间，偏移量相对于中间偏移
                        -385, //y坐标修正值。 默认在中间，偏移量相对于中间偏移
                        0.8f//透明度：alpha 必须是范围 [0.0, 1.0] 之内（包含边界值）的一个浮点数字
                );

                //第4步介绍
                String pro = "原价￥"+storeCombination.getProductPrice()+" 还差"
                        +storePinkService.surplusPeople(storePink)+"人拼团成功";
                ImgUtil.pressText(//
                        FileUtil.file(spreadPicPath),
                        FileUtil.file(spreadPicPath),
                        pro,
                        Color.BLACK,
                        f3, //字体
                        -50, //x坐标修正值。 默认在中间，偏移量相对于中间偏移
                        -300, //y坐标修正值。 默认在中间，偏移量相对于中间偏移
                        0.7f//透明度：alpha 必须是范围 [0.0, 1.0] 之内（包含边界值）的一个浮点数字
                );

                //第5步商品图片
                //下载图片
//                String picImage = fileDir+pinkId+"_pink_image.jpg";
//                HttpUtil.downloadFile(storeCombination.getImage(),
//                        FileUtil.file(picImage));

                String image = storeCombination.getImage();
                String ext = image.substring(image.lastIndexOf("."));
                String picImage = fileDir + "pink_product_" + pinkId + ext;
                if(!new File(picImage).exists()){
                    //下载商品图
                    HttpUtil.downloadFile(image, FileUtil.file(picImage));
                    //只缩放一次防止图片持续缩放导致图片没了
                    ImgUtil.scale(
                            FileUtil.file(picImage),
                            FileUtil.file(picImage),
                            0.5f//缩放比例
                    );
                }


                ImgUtil.pressImage(
                        FileUtil.file(spreadPicPath),
                        FileUtil.file(spreadPicPath),
                        ImgUtil.read(FileUtil.file(picImage)), //水印图片
                        0, //x坐标修正值。 默认在中间，偏移量相对于中间偏移
                        -80, //y坐标修正值。 默认在中间，偏移量相对于中间偏移
                        0.8f
                );

                ImgUtil.pressImage(
                        FileUtil.file(spreadPicPath),
                        FileUtil.file(spreadPicPath),
                        ImgUtil.read(FileUtil.file(qrcodeUrl)), //水印图片
                        0, //x坐标修正值。 默认在中间，偏移量相对于中间偏移
                        390, //y坐标修正值。 默认在中间，偏移量相对于中间偏移
                        0.8f
                );

                systemAttachmentService.attachmentAdd(spreadPicName,
                        String.valueOf(FileUtil.size(new File(spreadPicPath))),
                        spreadPicPath,"qrcode/"+spreadPicName);

                spreadUrl = apiUrl + "/api/file/qrcode/"+spreadPicName;

            } catch (Exception e) {
                log.error(e.getMessage());
                throw new YshopException(e.getMessage());
            }
        }else{
            spreadUrl = apiUrl + "/api/file/" + attachmentT.getSattDir();
        }

        return  spreadUrl;
    }

    /**
     * 获取推三返一海报
     * @param combinationId 拼团id
     * @param userInfo 用户
     * @param siteUrl h5地址
     * @param apiUrl api地址
     * @param path 本地图片路径
     * @return url
     */
    public String getPinkRebateUrl1(Long combinationId, YxUser userInfo,String siteUrl,
                                   String apiUrl,String path,String from){
        Long uid = userInfo.getUid();
        YxStoreCombination storeCombination = storeCombinationService.getById(combinationId);
        if(ObjectUtil.isNull(storeCombination)) {
            throw new YshopException("拼团产品不存在");
        }


        String name = combinationId+"_"+uid + "_"+from+"_pink_share_wap.jpg";
        YxSystemAttachment attachment = systemAttachmentService.getInfo(name);
        String fileDir = path+"qrcode"+ File.separator;
        String qrcodeUrl = "";
        String str ="id="+combinationId+"-spread="+uid+"-pageType=good";
        String url ="pages/activity/RebateDetails/index";
        if(ObjectUtil.isNull(attachment)){
            //生成二维码
            File file = FileUtil.mkdir(new File(fileDir));
            if(AppFromEnum.ROUNTINE.getValue().equals(from)){
                /*siteUrl = siteUrl+"/pink/";
                QrCodeUtil.generate(siteUrl+"?pinkId="+pinkId+"&spread="+uid+"&pageType=group&codeType="+AppFromEnum.ROUNTINE.getValue(), 180, 180,
                        FileUtil.file(fileDir+name));*/
                getminiqrQr(str,fileDir,name,url);
            }
            else if(AppFromEnum.APP.getValue().equals(from)){
                siteUrl = siteUrl+"/pink/";
                QrCodeUtil.generate(siteUrl+"?id="+combinationId+"&spread="+uid+"&pageType=group&codeType="+AppFromEnum.ROUNTINE.getValue(), 180, 180,
                        FileUtil.file(fileDir+name));
            }
            else if(AppFromEnum.H5.getValue().equals(from)){
                QrCodeUtil.generate(siteUrl+"/activity/group_rule/"+combinationId+"?spread="+uid, 180, 180,
                        FileUtil.file(fileDir+name));
            }else {
                String uniUrl = systemConfigService.getData(SystemConfigConstants.UNI_SITE_URL);
                siteUrl =  StrUtil.isNotBlank(uniUrl) ? uniUrl :  ShopConstants.DEFAULT_UNI_H5_URL;
                QrCodeUtil.generate(siteUrl+"/pages/activity/GroupRule/index?id="+combinationId+"&spread="+uid, 180, 180,
                        FileUtil.file(fileDir+name));
            }


            systemAttachmentService.attachmentAdd(name,String.valueOf(FileUtil.size(file)),
                    fileDir+name,"qrcode/"+name);

            qrcodeUrl = fileDir+name;
        }else{
            qrcodeUrl = attachment.getAttDir();
        }

        String spreadPicName = combinationId+"_"+uid + "_"+from+"_pink_user_spread.jpg";
        String spreadPicPath = fileDir+spreadPicName;

        YxSystemAttachment attachmentT = systemAttachmentService.getInfo(spreadPicName);
        String spreadUrl = "";
//        InputStream stream =  getClass().getClassLoader().getResourceAsStream("poster.jpg");
//        InputStream streamT =  getClass().getClassLoader()
//                .getResourceAsStream("simsunb.ttf");
        File newFile = new File("poster1.jpg");
        File newFileT = new File("simsunb.ttf");
        try {
            if(!newFileT.exists()){
                InputStream streamT =  getClass().getClassLoader()
                        .getResourceAsStream("simsunb.ttf");
                FileUtils.copyInputStreamToFile(streamT, newFileT);
            }
            if(!newFile.exists()){
                InputStream stream =  getClass().getClassLoader().getResourceAsStream("poster1.jpg");
                FileUtils.copyInputStreamToFile(stream, newFile);
            }

        } catch (IOException e) {
            log.error(e.getMessage());
            throw new YshopException(e.getMessage());
        }
        if(ObjectUtil.isNull(attachmentT)){
            try {

                //第一步标题
                Font font =  Font.createFont(Font.TRUETYPE_FONT, newFileT);
                Font f= font.deriveFont(Font.PLAIN,40);
                //font.
                ImgUtil.pressText(//
                        newFile,
                        FileUtil.file(spreadPicPath),
                        storeCombination.getTitle(),
                        Color.BLACK,
                        f, //字体
                        -160, //x坐标修正值。 默认在中间，偏移量相对于中间偏移
                        70, //y坐标修正值。 默认在中间，偏移量相对于中间偏移
                        0.8f//透明度：alpha 必须是范围 [0.0, 1.0] 之内（包含边界值）的一个浮点数字
                );

                Font f2= font.deriveFont(Font.PLAIN,45);
                //第2步价格
                ImgUtil.pressText(//
                        FileUtil.file(spreadPicPath),
                        FileUtil.file(spreadPicPath),
                        "￥"+storeCombination.getPrice().toString(),
                        Color.RED,
                        f2, //字体
                        -160, //x坐标修正值。 默认在中间，偏移量相对于中间偏移
                        130, //y坐标修正值。 默认在中间，偏移量相对于中间偏移
                        0.8f//透明度：alpha 必须是范围 [0.0, 1.0] 之内（包含边界值）的一个浮点数字
                );
                String temp ="三";
                if(storeCombination.getPeople() ==4){
                    temp ="四";
                }else if(storeCombination.getPeople() ==5){
                    temp ="五";
                }else if(storeCombination.getPeople() ==6){
                    temp ="六";
                }else if(storeCombination.getPeople() ==7){
                    temp ="七";
                }
                Font f3= font.deriveFont(Font.PLAIN,30);
                //第3步几人团
                ImgUtil.pressText(//
                        FileUtil.file(spreadPicPath),
                        FileUtil.file(spreadPicPath),
                        "推"+temp+"返一",
                        Color.RED,
                        f3, //字体
                        -160, //x坐标修正值。 默认在中间，偏移量相对于中间偏移
                        135, //y坐标修正值。 默认在中间，偏移量相对于中间偏移
                        0.8f//透明度：alpha 必须是范围 [0.0, 1.0] 之内（包含边界值）的一个浮点数字
                );
                int peoper = storeCombination.getPeople();
                int pinkOkSum =storePinkService.getPinkOk4selfRebateSumTotalNum(uid,storeCombination.getId());
                int remainder =peoper-pinkOkSum%peoper;//余数
                //第4步介绍
                String pro = "原价￥"+storeCombination.getProductPrice();
                ImgUtil.pressText(//
                        FileUtil.file(spreadPicPath),
                        FileUtil.file(spreadPicPath),
                        pro,
                        Color.BLACK,
                        f3, //字体
                        -50, //x坐标修正值。 默认在中间，偏移量相对于中间偏移
                        180, //y坐标修正值。 默认在中间，偏移量相对于中间偏移
                        0.7f//透明度：alpha 必须是范围 [0.0, 1.0] 之内（包含边界值）的一个浮点数字
                );

                //第5步商品图片
                //下载图片
//                String picImage = fileDir+pinkId+"_pink_image.jpg";
//                HttpUtil.downloadFile(storeCombination.getImage(),
//                        FileUtil.file(picImage));

                String image = storeCombination.getImage();
                String ext = image.substring(image.lastIndexOf("."));
                String picImage = fileDir + "pink_product_" + combinationId + ext;
                if(!new File(picImage).exists()){
                    //下载商品图
                    HttpUtil.downloadFile(image, FileUtil.file(picImage));
                    //只缩放一次防止图片持续缩放导致图片没了
                    ImgUtil.scale(
                            FileUtil.file(picImage),
                            FileUtil.file(picImage),
                            0.8f//缩放比例
                    );
                }


                ImgUtil.pressImage(
                        FileUtil.file(spreadPicPath),
                        FileUtil.file(spreadPicPath),
                        ImgUtil.read(FileUtil.file(picImage)), //水印图片
                        0, //x坐标修正值。 默认在中间，偏移量相对于中间偏移
                        -280, //y坐标修正值。 默认在中间，偏移量相对于中间偏移
                        0.8f
                );

                ImgUtil.pressImage(
                        FileUtil.file(spreadPicPath),
                        FileUtil.file(spreadPicPath),
                        ImgUtil.read(FileUtil.file(qrcodeUrl)), //水印图片
                        0, //x坐标修正值。 默认在中间，偏移量相对于中间偏移
                        350, //y坐标修正值。 默认在中间，偏移量相对于中间偏移
                        0.8f
                );

                systemAttachmentService.attachmentAdd(spreadPicName,
                        String.valueOf(FileUtil.size(new File(spreadPicPath))),
                        spreadPicPath,"qrcode/"+spreadPicName);

                spreadUrl = apiUrl + "/api/file/qrcode/"+spreadPicName;

            } catch (Exception e) {
                log.error(e.getMessage());
                throw new YshopException(e.getMessage());
            }
        }else{
            spreadUrl = apiUrl + "/api/file/" + attachmentT.getSattDir();
        }

        return  spreadUrl;
    }

    /**
     * 获取推三返一海报
     * @param userInfo 用户
     * @param apiUrl api地址
     * @return url
     */
    public String getPinkRebateUrl(YxStoreProduct productDTO, String shareCode, String spreadPicName, String spreadPicPath, String apiUrl,YxUser userInfo,Long combinationId,String image)  throws IOException, FontFormatException {
        YxSystemAttachment attachmentT = systemAttachmentService.getInfo(spreadPicName);
        String spreadUrl = "";
        if(ObjectUtil.isNull(attachmentT)){
            //创建图片
            BufferedImage img = new BufferedImage(750, 1134, BufferedImage.TYPE_INT_RGB);
            //开启画图
            Graphics g = img.getGraphics();
            //背景 -- 读取互联网图片
            InputStream stream =  getClass().getClassLoader().getResourceAsStream("background.png");
            ImageInputStream background = ImageIO.createImageInputStream(stream);
            BufferedImage back = ImageIO.read(background);

            g.drawImage(back.getScaledInstance(750, 1134, Image.SCALE_DEFAULT), 0, 0, null); // 绘制缩小后的图
            //商品  banner图
            //读取互联网图片
            BufferedImage priductUrl = null;
            try {
                priductUrl = ImageIO.read(new URL(transformStyle(image)));
            } catch (IOException e) {
                e.printStackTrace();
            }
            g.drawImage(priductUrl.getScaledInstance(750,750,Image.SCALE_DEFAULT),0,0,null);

            //File newFileT = new File("simsunb.ttf");
            File newFileT = new File("simsunb.ttf");
            if(!newFileT.exists()){
                InputStream streamT =  getClass().getClassLoader()
                        .getResourceAsStream("simsunb.ttf");
                FileUtils.copyInputStreamToFile(streamT, newFileT);
            }
            Font font =  Font.createFont(Font.TRUETYPE_FONT, newFileT);
            //文案标题
            /*g.setFont(font.deriveFont(Font.BOLD,34));
            g.setColor(new Color(29,29,29));
            int fontlenb = getWatermarkLength(productDTO.getStoreName(), g);
            //文字长度相对于图片宽度应该有多少行
            int lineb = fontlenb / (back.getWidth() +200);
            //高度
            int yb = back.getHeight() - (lineb + 1) * 30 + 100;
            //文字叠加,自动换行叠加
            int tempXb = 32;
            int tempYb = yb;
            //单字符长度
            int tempCharLenb = 0;
            //单行字符总长度临时计算
            int tempLineLenb = 0;
            StringBuffer sbb =new StringBuffer();
            for(int i=0; i < productDTO.getStoreName().length(); i++) {
                char tempChar = productDTO.getStoreName().charAt(i);
                tempCharLenb = getCharLen(tempChar, g);
                tempLineLenb += tempCharLenb;
                if(tempLineLenb >= (back.getWidth()+220)) {
                    //长度已经满一行,进行文字叠加
                    g.drawString(sbb.toString(), tempXb, tempYb + 50);
                    //清空内容,重新追加
                    sbb.delete(0, sbb.length());
                    //每行文字间距50
                    tempYb += 50;
                    tempLineLenb =0;
                }
                //追加字符
                sbb.append(tempChar);
            }
            g.drawString(sbb.toString(), tempXb, tempYb + 50);*/

            //------------------------------------------------文案-----------------------
            //文案
            g.setFont(font.deriveFont(Font.PLAIN,34));
            g.setColor(new Color(29,29,29));
            int fontlen = getWatermarkLength(productDTO.getStoreName(), g);
            //文字长度相对于图片宽度应该有多少行
            int line = fontlen / (back.getWidth() +200);
            //高度
            int y = back.getHeight() + 150 - (line + 1) * 30 + 70;
            //文字叠加,自动换行叠加
            int tempX = 32;
            int tempY = y;
            //单字符长度
            int tempCharLen = 0;
            //单行字符总长度临时计算
            int tempLineLen = 0;
            StringBuffer sb =new StringBuffer();

            for(int i=0; i < productDTO.getStoreName().length(); i++) {
                char tempChar = productDTO.getStoreName().charAt(i);
                tempCharLen = getCharLen(tempChar, g);
                tempLineLen += tempCharLen;
                if(tempLineLen >= (back.getWidth()+220)) {
                    //长度已经满一行,进行文字叠加
                    g.drawString(sb.toString(), tempX, tempY + 50);
                    //清空内容,重新追加
                    sb.delete(0, sb.length());
                    //每行文字间距50
                    tempY += 50;
                    tempLineLen =0;
                }
                //追加字符
                sb.append(tempChar);
            }
            //最后叠加余下的文字
            g.drawString(sb.toString(), tempX, tempY + 50);

            //价格背景
            //读取互联网图片
            /*BufferedImage bground  = null;//
            InputStream redStream =  getClass().getClassLoader().getResourceAsStream("red.jpg");
            try {
                ImageInputStream red = ImageIO.createImageInputStream(redStream);
                bground = ImageIO.read(red);
            } catch (IOException e) {
                e.printStackTrace();
            }
            // 绘制缩小后的图
            g.drawImage(bground.getScaledInstance(160, 40, Image.SCALE_DEFAULT), 30, 853, null);
*/
            //限时促销价
            /*g.setFont(font.deriveFont(Font.PLAIN,24));
            g.setColor(new Color(255,255,255));
            g.drawString("限时促销价", 50, 1080);*/

            //价格
            g.setFont(font.deriveFont(Font.PLAIN,30));
            g.setColor(new Color(249,64,64));
            g.drawString("抢购价" +productDTO.getPrice()+"积分", 29, 862);

            //原价
            /*g.setFont(font.deriveFont(Font.PLAIN,36));
            g.setColor(new Color(171,171,171));
            String price = "¥" + productDTO.getOtPrice();
            g.drawString(price, 260, 898);
            g.drawLine(250,898,260+150,898);*/

            BufferedImage wxHeadUrl  = null;
            String headimgurl ="https://h5.ylsp.vip/file/static/avatar.jpg";
            log.info("headimgurl==============="+headimgurl);
            log.info("WxProfile==============="+userInfo.getWxProfile().getHeadimgurl());
            if(ObjectUtil.isNotEmpty(userInfo.getWxProfile().getHeadimgurl())){
                headimgurl =userInfo.getWxProfile().getHeadimgurl();
            }
            log.info("headimgurl3333333333333==============="+headimgurl);
            try {
                wxHeadUrl = ImageIO.read(new URL(headimgurl));
            } catch (IOException e) {
                e.printStackTrace();
            }
            // 绘制缩小后的图
            g.drawImage(wxHeadUrl.getScaledInstance(114, 114, Image.SCALE_DEFAULT), 29, 917, null);
            String nickname =userInfo.getWxProfile().getNickname();
            if(nickname.length()>8){
                nickname =nickname.substring(0,7)+"...";
            }
            //微信名称
            g.setFont(font.deriveFont(Font.PLAIN,30));
            g.setColor(new Color(0,0,0));
            g.drawString(nickname, 155, 937);

            //邀请语录
            g.setFont(font.deriveFont(Font.PLAIN,25));
            g.setColor(new Color(156,186,188));
            g.drawString("邀请您来予礼新零售商城", 155, 967);

            //邀请语录
            g.setFont(font.deriveFont(Font.PLAIN,25));
            g.setColor(new Color(156,186,188));
            g.drawString("享受品牌会员权益", 155, 997);

//            //商品名称
//            g.setFont(font.deriveFont(Font.PLAIN,32));
//            g.setColor(new Color(29,29,29));
//            g.drawString(productDTO.getStoreName(), 30, 1229);

            //生成二维码返回链接
            String url = shareCode;
            //读取互联网图片
            BufferedImage qrCode  = null;
            log.info("url==========="+url);
            try {
                qrCode = ImageIO.read(new URL(url));
            } catch (IOException e) {
                e.printStackTrace();
            }
            log.info("qrCode==========="+qrCode);
            // 绘制缩小后的图
            g.drawImage(qrCode.getScaledInstance(174, 174, Image.SCALE_DEFAULT), 536, 857, null);

            //二维码字体
           /* g.setFont(font.deriveFont(Font.PLAIN,25));
            g.setColor(new Color(171,171,171));
            //绘制文字
            g.drawString("扫描或长按小程序码", 515, 960);*/

            g.dispose();
            //先将画好的海报写到本地
            File file = new File(spreadPicPath);
            try {
                ImageIO.write(img, "jpg",file);
            } catch (IOException e) {
                e.printStackTrace();
            }
            systemAttachmentService.newAttachment4SpreadAdd(spreadPicName,
                    String.valueOf(FileUtil.size(new File(spreadPicPath))),
                    spreadPicPath,"qrcode/"+spreadPicName,userInfo.getUid(),"","3",combinationId);
            spreadUrl = apiUrl + "/api/file/qrcode/"+spreadPicName;
            //保存到本地 生成文件名字
        }else{
            spreadUrl = apiUrl + "/api/file/" + attachmentT.getSattDir();
        }
        return spreadUrl;
    }

    /**
     * 获取秒杀海报
     * @param userInfo 用户
     * @param apiUrl api地址
     * @return url
     */
    public String getSeckillRebateUrl(YxStoreProduct productDTO, String shareCode, String spreadPicName, String spreadPicPath, String apiUrl,YxUser userInfo,Long seckillId,String image)  throws IOException, FontFormatException {
        YxSystemAttachment attachmentT = systemAttachmentService.getInfo(spreadPicName);
        log.info("开始===============");
        log.info("用户ID==============="+userInfo.getUid());
        log.info("attachmentT==============="+attachmentT);
        String spreadUrl = "";
        if(ObjectUtil.isNull(attachmentT)){
            //创建图片
            BufferedImage img = new BufferedImage(750, 1134, BufferedImage.TYPE_INT_RGB);
            //开启画图
            Graphics g = img.getGraphics();
            //背景 -- 读取互联网图片
            InputStream stream =  getClass().getClassLoader().getResourceAsStream("background.png");
            ImageInputStream background = ImageIO.createImageInputStream(stream);
            BufferedImage back = ImageIO.read(background);

            g.drawImage(back.getScaledInstance(750, 1134, Image.SCALE_DEFAULT), 0, 0, null); // 绘制缩小后的图
            //商品  banner图
            //读取互联网图片
            BufferedImage priductUrl = null;
            try {
                priductUrl = ImageIO.read(new URL(transformStyle(image)));
            } catch (IOException e) {
                e.printStackTrace();
            }
            g.drawImage(priductUrl.getScaledInstance(750,750,Image.SCALE_DEFAULT),0,0,null);

            //File newFileT = new File("simsunb.ttf");
            File newFileT = new File("simsunb.ttf");
            if(!newFileT.exists()){
                InputStream streamT =  getClass().getClassLoader()
                        .getResourceAsStream("simsunb.ttf");
                FileUtils.copyInputStreamToFile(streamT, newFileT);
            }
            Font font =  Font.createFont(Font.TRUETYPE_FONT, newFileT);
            //文案标题
            /*g.setFont(font.deriveFont(Font.BOLD,34));
            g.setColor(new Color(29,29,29));
            int fontlenb = getWatermarkLength(productDTO.getStoreName(), g);
            //文字长度相对于图片宽度应该有多少行
            int lineb = fontlenb / (back.getWidth() +200);
            //高度
            int yb = back.getHeight() - (lineb + 1) * 30 + 100;
            //文字叠加,自动换行叠加
            int tempXb = 32;
            int tempYb = yb;
            //单字符长度
            int tempCharLenb = 0;
            //单行字符总长度临时计算
            int tempLineLenb = 0;
            StringBuffer sbb =new StringBuffer();
            for(int i=0; i < productDTO.getStoreName().length(); i++) {
                char tempChar = productDTO.getStoreName().charAt(i);
                tempCharLenb = getCharLen(tempChar, g);
                tempLineLenb += tempCharLenb;
                if(tempLineLenb >= (back.getWidth()+220)) {
                    //长度已经满一行,进行文字叠加
                    g.drawString(sbb.toString(), tempXb, tempYb + 50);
                    //清空内容,重新追加
                    sbb.delete(0, sbb.length());
                    //每行文字间距50
                    tempYb += 50;
                    tempLineLenb =0;
                }
                //追加字符
                sbb.append(tempChar);
            }
            g.drawString(sbb.toString(), tempXb, tempYb + 50);*/

            //------------------------------------------------文案-----------------------
            //文案
            g.setFont(font.deriveFont(Font.PLAIN,34));
            g.setColor(new Color(29,29,29));
            int fontlen = getWatermarkLength(productDTO.getStoreName(), g);
            //文字长度相对于图片宽度应该有多少行
            int line = fontlen / (back.getWidth() +200);
            //高度
            int y = back.getHeight() + 150 - (line + 1) * 30 + 70;
            //文字叠加,自动换行叠加
            int tempX = 32;
            int tempY = y;
            //单字符长度
            int tempCharLen = 0;
            //单行字符总长度临时计算
            int tempLineLen = 0;
            StringBuffer sb =new StringBuffer();

            for(int i=0; i < productDTO.getStoreName().length(); i++) {
                char tempChar = productDTO.getStoreName().charAt(i);
                tempCharLen = getCharLen(tempChar, g);
                tempLineLen += tempCharLen;
                if(tempLineLen >= (back.getWidth()+220)) {
                    //长度已经满一行,进行文字叠加
                    g.drawString(sb.toString(), tempX, tempY + 50);
                    //清空内容,重新追加
                    sb.delete(0, sb.length());
                    //每行文字间距50
                    tempY += 50;
                    tempLineLen =0;
                }
                //追加字符
                sb.append(tempChar);
            }
            //最后叠加余下的文字
            g.drawString(sb.toString(), tempX, tempY + 50);

            //价格背景
            //读取互联网图片
            /*BufferedImage bground  = null;//
            InputStream redStream =  getClass().getClassLoader().getResourceAsStream("red.jpg");
            try {
                ImageInputStream red = ImageIO.createImageInputStream(redStream);
                bground = ImageIO.read(red);
            } catch (IOException e) {
                e.printStackTrace();
            }
            // 绘制缩小后的图
            g.drawImage(bground.getScaledInstance(160, 40, Image.SCALE_DEFAULT), 30, 853, null);
*/
            //限时促销价
            /*g.setFont(font.deriveFont(Font.PLAIN,24));
            g.setColor(new Color(255,255,255));
            g.drawString("限时促销价", 50, 1080);*/

            //价格
            g.setFont(font.deriveFont(Font.PLAIN,30));
            g.setColor(new Color(249,64,64));
            g.drawString("抢购价" +productDTO.getPrice()+"积分", 29, 862);

            //原价
            /*g.setFont(font.deriveFont(Font.PLAIN,36));
            g.setColor(new Color(171,171,171));
            String price = "¥" + productDTO.getOtPrice();
            g.drawString(price, 260, 898);
            g.drawLine(250,898,260+150,898);*/

            BufferedImage wxHeadUrl  = null;
            String headimgurl ="https://h5.ylsp.vip/file/static/avatar.jpg";
            log.info("headimgurl==============="+headimgurl);
            log.info("WxProfile==============="+userInfo.getWxProfile().getHeadimgurl());
            if(ObjectUtil.isNotEmpty(userInfo.getWxProfile().getHeadimgurl())){
                headimgurl =userInfo.getWxProfile().getHeadimgurl();
            }
            log.info("headimgurl3333333333333==============="+headimgurl);
            try {
                wxHeadUrl = ImageIO.read(new URL(headimgurl));
            } catch (IOException e) {
                e.printStackTrace();
            }
            // 绘制缩小后的图
            g.drawImage(wxHeadUrl.getScaledInstance(114, 114, Image.SCALE_DEFAULT), 29, 917, null);
            String nickname =userInfo.getWxProfile().getNickname();
            if(nickname.length()>8){
                nickname =nickname.substring(0,7)+"...";
            }
            //微信名称
            g.setFont(font.deriveFont(Font.PLAIN,30));
            g.setColor(new Color(0,0,0));
            g.drawString(nickname, 155, 937);

            //邀请语录
            g.setFont(font.deriveFont(Font.PLAIN,25));
            g.setColor(new Color(156,186,188));
            g.drawString("邀请您来予礼新零售商城", 155, 967);

            //邀请语录
            g.setFont(font.deriveFont(Font.PLAIN,25));
            g.setColor(new Color(156,186,188));
            g.drawString("享受品牌会员权益", 155, 997);

//            //商品名称
//            g.setFont(font.deriveFont(Font.PLAIN,32));
//            g.setColor(new Color(29,29,29));
//            g.drawString(productDTO.getStoreName(), 30, 1229);

            //生成二维码返回链接
            String url = shareCode;
            //读取互联网图片
            BufferedImage qrCode  = null;
            log.info("url==========="+url);
            try {
                qrCode = ImageIO.read(new URL(url));
            } catch (IOException e) {
                e.printStackTrace();
            }
            log.info("qrCode==========="+qrCode);
            // 绘制缩小后的图
            g.drawImage(qrCode.getScaledInstance(174, 174, Image.SCALE_DEFAULT), 536, 857, null);

            //二维码字体
           /* g.setFont(font.deriveFont(Font.PLAIN,25));
            g.setColor(new Color(171,171,171));
            //绘制文字
            g.drawString("扫描或长按小程序码", 515, 960);*/

            g.dispose();
            //先将画好的海报写到本地
            File file = new File(spreadPicPath);
            try {
                ImageIO.write(img, "jpg",file);
            } catch (IOException e) {
                e.printStackTrace();
            }
            systemAttachmentService.newAttachment4SpreadAdd(spreadPicName,
                    String.valueOf(FileUtil.size(new File(spreadPicPath))),
                    spreadPicPath,"qrcode/"+spreadPicName,userInfo.getUid(),"","4",seckillId);
            spreadUrl = apiUrl + "/api/file/qrcode/"+spreadPicName;
            //保存到本地 生成文件名字
        }else{
            spreadUrl = apiUrl + "/api/file/" + attachmentT.getSattDir();
            log.info("spreadUrl111==============="+spreadUrl);
        }
        log.info("结束===============");
        log.info("spreadUrl2222==============="+spreadUrl);
        return spreadUrl;
    }


    /**
     * 普通组合海报
     * @param productDTO 商品
     * @param shareCode 二维码
     * @param spreadPicName 海报图片名称
     * @param spreadPicPath 路径
     * @param apiUrl api地址
     * @return String
     * @throws IOException
     * @throws FontFormatException
     */
    public  String creatProductPic(YxStoreProduct productDTO, String shareCode, String spreadPicName, String spreadPicPath, String apiUrl,YxUser userInfo) throws IOException, FontFormatException {
        YxSystemAttachment attachmentT = systemAttachmentService.getInfo(spreadPicName);
        String spreadUrl = "";
        log.info("开始===============");
        log.info("用户ID==============="+userInfo.getUid());
        log.info("attachmentT==============="+attachmentT);
        if(ObjectUtil.isNull(attachmentT)){
            //创建图片
            BufferedImage img = new BufferedImage(750, 1134, BufferedImage.TYPE_INT_RGB);
            //开启画图
            Graphics g = img.getGraphics();
            //背景 -- 读取互联网图片
            InputStream stream =  getClass().getClassLoader().getResourceAsStream("background.png");
            ImageInputStream background = ImageIO.createImageInputStream(stream);
            BufferedImage back = ImageIO.read(background);

            g.drawImage(back.getScaledInstance(750, 1134, Image.SCALE_DEFAULT), 0, 0, null); // 绘制缩小后的图
            //商品  banner图
            //读取互联网图片
            BufferedImage priductUrl = null;
            try {
                priductUrl = ImageIO.read(new URL(transformStyle(productDTO.getImage())));
            } catch (IOException e) {
                e.printStackTrace();
            }
            g.drawImage(priductUrl.getScaledInstance(750,750,Image.SCALE_DEFAULT),0,0,null);

            //File newFileT = new File("simsunb.ttf");
            File newFileT = new File("simsunb.ttf");
            if(!newFileT.exists()){
                InputStream streamT =  getClass().getClassLoader()
                        .getResourceAsStream("simsunb.ttf");
                FileUtils.copyInputStreamToFile(streamT, newFileT);
            }
            Font font =  Font.createFont(Font.TRUETYPE_FONT, newFileT);
            //文案标题
            /*g.setFont(font.deriveFont(Font.BOLD,34));
            g.setColor(new Color(29,29,29));
            int fontlenb = getWatermarkLength(productDTO.getStoreName(), g);
            //文字长度相对于图片宽度应该有多少行
            int lineb = fontlenb / (back.getWidth() +200);
            //高度
            int yb = back.getHeight() - (lineb + 1) * 30 + 100;
            //文字叠加,自动换行叠加
            int tempXb = 32;
            int tempYb = yb;
            //单字符长度
            int tempCharLenb = 0;
            //单行字符总长度临时计算
            int tempLineLenb = 0;
            StringBuffer sbb =new StringBuffer();
            for(int i=0; i < productDTO.getStoreName().length(); i++) {
                char tempChar = productDTO.getStoreName().charAt(i);
                tempCharLenb = getCharLen(tempChar, g);
                tempLineLenb += tempCharLenb;
                if(tempLineLenb >= (back.getWidth()+220)) {
                    //长度已经满一行,进行文字叠加
                    g.drawString(sbb.toString(), tempXb, tempYb + 50);
                    //清空内容,重新追加
                    sbb.delete(0, sbb.length());
                    //每行文字间距50
                    tempYb += 50;
                    tempLineLenb =0;
                }
                //追加字符
                sbb.append(tempChar);
            }
            g.drawString(sbb.toString(), tempXb, tempYb + 50);*/

            //------------------------------------------------文案-----------------------
            //文案
            g.setFont(font.deriveFont(Font.PLAIN,34));
            g.setColor(new Color(0,0,0));
            int fontlen = getWatermarkLength(productDTO.getStoreName(), g);
            //文字长度相对于图片宽度应该有多少行
            int line = fontlen / (back.getWidth() +200);
            //高度
            int y = back.getHeight() + 150 - (line + 1) * 30 + 70;
            //文字叠加,自动换行叠加
            int tempX = 32;
            int tempY = y;
            //单字符长度
            int tempCharLen = 0;
            //单行字符总长度临时计算
            int tempLineLen = 0;
            StringBuffer sb =new StringBuffer();

            for(int i=0; i < productDTO.getStoreName().length(); i++) {
                char tempChar = productDTO.getStoreName().charAt(i);
                tempCharLen = getCharLen(tempChar, g);
                tempLineLen += tempCharLen;
                if(tempLineLen >= (back.getWidth()+220)) {
                    //长度已经满一行,进行文字叠加
                    g.drawString(sb.toString(), tempX, tempY + 50);
                    //清空内容,重新追加
                    sb.delete(0, sb.length());
                    //每行文字间距50
                    tempY += 50;
                    tempLineLen =0;
                }
                //追加字符
                sb.append(tempChar);
            }
            //最后叠加余下的文字
            g.drawString(sb.toString(), tempX, tempY + 50);

            //价格背景
            //读取互联网图片
            /*BufferedImage bground  = null;//
            InputStream redStream =  getClass().getClassLoader().getResourceAsStream("red.jpg");
            try {
                ImageInputStream red = ImageIO.createImageInputStream(redStream);
                bground = ImageIO.read(red);
            } catch (IOException e) {
                e.printStackTrace();
            }
            // 绘制缩小后的图
            g.drawImage(bground.getScaledInstance(160, 40, Image.SCALE_DEFAULT), 30, 853, null);
*/
            //限时促销价
            /*g.setFont(font.deriveFont(Font.PLAIN,24));
            g.setColor(new Color(255,255,255));
            g.drawString("限时促销价", 50, 1080);*/

            //价格
            g.setFont(font.deriveFont(Font.PLAIN,30));
            g.setColor(new Color(249,64,64));
            g.drawString("抢购价" +productDTO.getPrice()+"积分", 29, 862);

            //原价
            /*g.setFont(font.deriveFont(Font.PLAIN,36));
            g.setColor(new Color(171,171,171));
            String price = "¥" + productDTO.getOtPrice();
            g.drawString(price, 260, 898);
            g.drawLine(250,898,260+150,898);*/

            BufferedImage wxHeadUrl  = null;
            String headimgurl ="https://h5.ylsp.vip/file/static/avatar.jpg";
            log.info("headimgurl==============="+headimgurl);
            log.info("WxProfile==============="+userInfo.getWxProfile().getHeadimgurl());
            if(ObjectUtil.isNotEmpty(userInfo.getWxProfile().getHeadimgurl())){
                headimgurl =userInfo.getWxProfile().getHeadimgurl();
            }
            log.info("headimgurl3333333333333==============="+headimgurl);
            try {
                wxHeadUrl = ImageIO.read(new URL(headimgurl));
            } catch (IOException e) {
                e.printStackTrace();
            }
            // 绘制缩小后的图
            g.drawImage(wxHeadUrl.getScaledInstance(114, 114, Image.SCALE_DEFAULT), 29, 917, null);
            String nickname =userInfo.getWxProfile().getNickname();
            if(nickname.length()>8){
                nickname =nickname.substring(0,7)+"...";
            }
            //微信名称
            g.setFont(font.deriveFont(Font.PLAIN,30));
            g.setColor(new Color(0,0,0));
            g.drawString(nickname, 155, 937);

            //邀请语录
            g.setFont(font.deriveFont(Font.PLAIN,25));
            g.setColor(new Color(0,0,0));
            g.drawString("邀请您来聚抖国际，", 155, 967);

            //邀请语录
            g.setFont(font.deriveFont(Font.PLAIN,25));
            g.setColor(new Color(0,0,0));
            g.drawString("马上开启黑科技抖音带货之路！", 155, 997);

//            //商品名称
//            g.setFont(font.deriveFont(Font.PLAIN,32));
//            g.setColor(new Color(29,29,29));
//            g.drawString(productDTO.getStoreName(), 30, 1229);

            //生成二维码返回链接
            String url = shareCode;
            //读取互联网图片
            BufferedImage qrCode  = null;
            try {
                qrCode = ImageIO.read(new URL(url));
            } catch (IOException e) {
                e.printStackTrace();
            }
            // 绘制缩小后的图
            g.drawImage(qrCode.getScaledInstance(174, 174, Image.SCALE_DEFAULT), 536, 857, null);

            //二维码字体
           /* g.setFont(font.deriveFont(Font.PLAIN,25));
            g.setColor(new Color(171,171,171));
            //绘制文字
            g.drawString("扫描或长按小程序码", 515, 960);*/

            g.dispose();
            //先将画好的海报写到本地
            File file = new File(spreadPicPath);
            try {
                ImageIO.write(img, "jpg",file);
            } catch (IOException e) {
                e.printStackTrace();
            }
            systemAttachmentService.newAttachment4SpreadAdd(spreadPicName,
                    String.valueOf(FileUtil.size(new File(spreadPicPath))),
                    spreadPicPath,"qrcode/"+spreadPicName,userInfo.getUid(),"","1",productDTO.getId());
            spreadUrl = apiUrl + "/api/file/qrcode/"+spreadPicName;
            //保存到本地 生成文件名字
        }else {
            spreadUrl = apiUrl + "/api/file/" + attachmentT.getSattDir();
            log.info("spreadUrl==============="+spreadUrl);
        }
        log.info("结束===============");
        log.info("spreadUrl==============="+spreadUrl);
        return spreadUrl;
    }


    /**
     * 获取水印文字总长度
     *@paramwaterMarkContent水印的文字
     *@paramg
     *@return水印文字总长度
     */
    public static int getWatermarkLength(String waterMarkContent, Graphics g) {
        return g.getFontMetrics(g.getFont()).charsWidth(waterMarkContent.toCharArray(),0, waterMarkContent.length());
    }
    public static int getCharLen(char c, Graphics g) {
        return g.getFontMetrics(g.getFont()).charWidth(c);
    }

    /*public String getToken() {
        RestTemplate rest = new RestTemplate();
        InputStream inputStream = null;
        OutputStream outputStream = null;
        String appId = redisUtils.getY(ShopKeyUtils.getWxAppAppId());
        String secret = redisUtils.getY(ShopKeyUtils.getWxAppSecret());
        try {
            Map<String, String> map = new LinkedHashMap<String, String>();
            map.put("grant_type", "client_credential");
            map.put("appid", appId);// 改成自己的appid
            map.put("secret", secret); //改成自己的secret
            MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
            HttpEntity requestEntity = new HttpEntity(map, headers);
            String url ="https://api.weixin.qq.com/cgi-bin/token";
            ResponseEntity<byte[]> entity = rest.exchange(url, HttpMethod.POST, requestEntity, byte[].class,
                    new Object[0]);
            byte[] result = entity.getBody();
            inputStream = new ByteArrayInputStream(result);

            String rt = Base64.getEncoder().encodeToString(inputStreamToByte(inputStream));
            //String rt = sendPost("https://api.weixin.qq.com/cgi-bin/token", map);
            //JSONObject json = JSONObject.parseObject(rt);
            if (rt != null || rt != "") {
                System.out.println("token:" + rt);
                return rt;
            } else {
                return null;
            }
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }finally {
            if (inputStream != null) {
                try {
                    inputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (outputStream != null) {
                try {
                    outputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }*/


    public void getminiqrQr(String sceneStr,String path,String name,String url) {
        OutputStream outputStream = null;
        InputStream inputStream = null;
        try {
            WxMaService wxMaService = WxMaConfiguration.getWxMaService();
            WxMaQrcodeService wxMaQrcodeService = wxMaService.getQrcodeService();
            File file = new File(path+name);
            if (!file.exists()){
                file.createNewFile();
            }
            outputStream = new FileOutputStream(file);
            WxMaCodeLineColor line_color = new WxMaCodeLineColor("0","0","0");
            byte[] qrCodeBytes = wxMaQrcodeService.createWxaCodeUnlimitBytes(sceneStr, url, 130, false, line_color, true);
            inputStream = new ByteArrayInputStream(qrCodeBytes);
            int len = 0;
            while ((len = inputStream.read(qrCodeBytes, 0, 1024)) != -1) {
                outputStream.write(qrCodeBytes, 0, len);
            }
            outputStream.flush();
        } catch (Exception ex) {
            log.info("生成小程序码失败，message:{}", ex.getMessage());
        } finally {
            try {
                outputStream.close();
            } catch (Exception ex) {
                log.error("关闭IO流失败,msg:{}", ex.getMessage());
            }
            if (inputStream != null) {
                try {
                    inputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }


    /*private static byte[] inputStreamToByte(InputStream inputStream) throws IOException{
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        int index = -1;
        while((index = inputStream.read()) != -1){
            baos.write(index);
        }
        return baos.toByteArray();
    }*/
}
